package com.itheima.dto;

import com.alibaba.fastjson.JSON;
import com.itheima.entity.SysUser;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
public class UserDTO {
    private String id;
    private String name;
    private String login_name;
    private String password;
    private String email;
    private String phone;
    private List<String> role_id;
    private Integer status;

    public SysUser transformSysUser(){
        SysUser sysUser = new SysUser();
        sysUser.setId(this.id);
        sysUser.setLoginName(this.login_name);
        sysUser.setPassword(this.password);
        sysUser.setName(this.name);
        sysUser.setEmail(this.email);
        sysUser.setPhone(this.phone);
        //sysUser.setLoginIp();
        sysUser.setLoginDate(LocalDateTime.now());
        //sysUser.setCreateDate();
        //sysUser.setUpdateDate();
        //sysUser.setDelFlag();
        //集合转JSON字符串
        String roleID = JSON.toJSONString(this.role_id);
        sysUser.setRoleId(roleID);
        sysUser.setStatus(this.status);
        //sysUser.setDefaultData();
        return sysUser;
    }
}
